package com.xindaoapp.henghua.utils;

import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.View.OnClickListener;

public class TabManager {
	private View[] mViews;
	private ViewPager mViewPager;
	public TabManager(View[] views, ViewPager viewPager) {
		this.mViews = views;
		this.mViewPager = viewPager;
		initListener();
	}

	private void initListener() {
		for (int i = 0; i < mViews.length; i++) {
			final int temp = i;
			mViews[i].setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View arg0) {
					mViewPager.setCurrentItem(temp);
				}
			});
		}
	}
	
	public void setTabViews(View[] views) {
		this.mViews = views;
	}
	
	public void selected(int position) {
		for (int i = 0; i < mViews.length; i++) {
			if (position == i) {
				mViews[i].setSelected(true);
			} else {
				mViews[i].setSelected(false);
			}
		}
	}
	
}
